/**
 *
 * ......................我佛慈悲.......................
 *                       _oo0oo_
 *                      o8888888o
 *                      88" . "88
 *                      (| -_- |)
 *                      0\  =  /0
 *                    ___/`---'\___
 *                  .' \\|     |// '.
 *                 / \\|||  :  |||// \
 *                / _||||| -卍-|||||- \
 *               |   | \\\  -  /// |   |
 *               | \_|  ''\---/''  |_/ |
 *               \  .-\__  '-'  ___/-. /
 *             ___'. .'  /--.--\  `. .'___
 *          ."" '<  `.___\_<|>_/___.' >' "".
 *         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
 *         \  \ `_.   \_ __\ /__ _/   .-` /  /
 *     =====`-.____`.___ \_____/___.-`___.-'=====
 *                       `=---='
 *
 *..................佛祖开光 ,永无BUG....................
 *         CSDN博客:http://blog.csdn.net/song5347
 *       github地址:https://github.com/lingsuiderongyan
 *             邮箱:lingsuiderongyan@163.com
 */

import UIKit

//微博模型
class LSStatus: NSObject {
    
    //发微博时间
    var created_at: String?
    //微博id
    var id: Int64 = 0
    //微博内容
    var text: String?
    //来源
    var source: String?
    //关注用户的模型
    var user: LSUser?
    //转发数
    var reposts_count: Int = 0
    //评论数
    var comments_count:	Int = 0
    //表态数
    var attitudes_count: Int = 0
    //转发微博对象
    var retweeted_status: LSStatus?
    //匹配信息
    var pic_urls: [LSStatusPictureInfo]?
    
    //kvc构造函数
    init(dic: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dic)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            guard let dic = value as? [String: AnyObject] else {
                return
            }
            
            //代码到此,字典没有问题
            user = LSUser(dic: dic)
        } else if key == "retweeted_status" {
            
            guard let dic = value as? [String: AnyObject] else {
                return
            }
            //代码执行到此,字典没有问题
            retweeted_status = LSStatus(dic: dic)
            
        }else if key == "pic_urls" {
            
            guard let dicArray = value as? [[String: AnyObject]] else {
                return
            }
            
            //代码执行到此,数组字典没有问题
            var tempArray = [LSStatusPictureInfo]()
            for dic in dicArray {
                let pictureInfo = LSStatusPictureInfo(dic: dic)
                tempArray.append(pictureInfo)
            }
            //  设置模型数据
            pic_urls = tempArray

            
        } else {
            super.setValue(value, forKey: key)
        }
    }
    
    //防止字段不匹配,导致崩溃
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
}
